<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const str = "2012-12-23";
      //整体匹配捕捉， 括号中内容会被单独捕捉
      console.log(str.match(/^(\d{4})-(\d{2})-(\d{2})$/));
      console.log(str.match(/^(\d{4})-((\d{2})-(\d{2}))$/));
    </script>
  </body>
</html>
